package mest.service.hws.impl;

import com.alibaba.fastjson.JSON;
import mest.dao.hws.plan_productjob_workfinish_recordMapper;
import mest.entity.plan_productjob_workfinish_record;
import mest.service.hws.plan_productjob_workfinishService;
import mest.service.hws.plan_productjob_workfinish_recordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor=Exception.class)
public class plan_productjob_workfinish_recordServiceImpl implements plan_productjob_workfinish_recordService {

    @Resource
    private plan_productjob_workfinish_recordMapper ppwr;

    @Resource
    private plan_productjob_workfinishService ppw;

    /*/insertModel /delModel /updateByone  selectById  selectAll */
    @Override
    public String insertModel(List<Map<String, Object>> map) {
        /*/insertModel /delModel /updateByone*/
        System.out.println("进入增删改方法");
        System.out.println(map);
        Map<String, Object> map1 = new HashMap<String, Object>();
        try {
                int count = ppwr.insert(map);
                int j =  ppw.updateByone(map);
            System.out.println("新增操作记录"+count+"条，修改内容表下达数量"+j+"条");
                map1.put("code", 0);
                map1.put("msg", "操作成功");
                map1.put("count",count);
        }catch (Exception e){
            map1.put("code", 1);
            map1.put("msg", "操作失败");
            e.toString();
        }    
        return JSON.toJSONString(map1);
    }

    @Override
    public Map<String,Object> selectAll(Map<String, Object> map) {
        /* selectById  selectAll  */
        System.out.println("进入查询");
        Map<String,Object> returnmap = new HashMap<String,Object>();
        try {
            map.put("page",(Integer.parseInt(map.get("page").toString())-1)*Integer.parseInt(map.get("limit").toString()));
            returnmap.put("code",0);
            returnmap.put("msg","查询成功");
            returnmap.put("count",ppwr.selectcount(map));
            returnmap.put("data",ppwr.selectAll(map));
        }catch (Exception e){
                System.out.println(e.toString());
            returnmap.put("code",1);
            returnmap.put("msg","查询失败");
            returnmap.put("errmsg",e.toString());
        }
        return returnmap;
    }
}
